<include file="Public:header" />
<script type="text/javascript" src="__PUBLIC__/style/js/TableFreeze.js"></script>
<style type="text/css">
	body{overflow-y: hidden;}
	.active {font-weight: 600;color: #000;}
	.nav.nav-tabs-left li{width:100%;}
	.nav-tabs-left>li.active>a{border-top:white;color: #19aa8d !important;background-color:#fff;}
	.ibox-span{float:left;margin-left:30px;line-height:30px;}
	.table tbody tr {cursor: Default;}
</style>
<script>
$(function(){
	var scroll_width = 5;
	$("#table_div").height(window.innerHeight-$("#table_div").offset().top-$("#tfoot_div").height()-parseInt($("#table_container").css("padding-bottom").replace("px",""))-60);
	$(window).resize(function(){
		$("#table_div").height(window.innerHeight-$("#table_div").offset().top-$("#tfoot_div").height()-parseInt($("#table_container").css("padding-bottom").replace("px",""))-60);
		$("#oDivL_tab_Test3").height($("#table_div").height()-scroll_width-1).width($("#oTableLH_tab_Test3").width());
		$("#oDivH_tab_Test3").height($("#oTableLH_tab_Test3").height()).width($("#table_div").width()-scroll_width);
	})
	if ("{$Think.get.by}") {
		$("#filter_ul").prev().html($("#filter_ul>li>a.active").text()+'<span class="fa fa-angle-down small_fa"></span>');
	}
	$("#tab_Test3").FrozenTable(1,0,0);
	$("#oDivL_tab_Test3").height($("#table_div").height()-scroll_width).width($("#oTableLH_tab_Test3").width());
	$("#oDivH_tab_Test3").height($("#oTableLH_tab_Test3").height()).width($("#table_div").width()-scroll_width);
})
</script>
<div class="wrapper wrapper-content" >
	<include file="Public:alert" />
    <div class="row">
        <div class="col-lg-12">
			<include file="Setting:setting_left" />
			<div class="col-md-10">
				<div id="table_container" style="border-top:3px solid #e7eaec;">
					<div class="title-bar">
						<div class="row  clearfix" id="title-hide" style="display:none;">
							<ul class="breadcrum pull-left">
								<li>已选中&nbsp;<span id="icheck_num"></span>&nbsp;项</li>
								<li id="user_span" ><a id="delete" href="javascript:void(0)" onclick="del_user(1)"><i class="fa fa-times"></i>&nbsp;停用账号</a></li>
								<li class="single_btn"><a href="javascript:void(0)" id="edit_user"><i class="fa fa-pencil"></i>&nbsp;修改信息</a></li>
								<li class="single_btn"><a href="javascript:void(0);" id="reset_password" class="link"><i class="fa fa-download"></i>&nbsp;重置密码</a></li>
								<li class="last_li"><big><a class="fa fa-times pull-right" id="back-show"></a></big></li>
							</ul>
						</div>
						<div class="row " id="title-show">
							<div class="nav pull-left" style="margin:2px 0 0 15px;">
								<if condition = "session('?admin') || checkPerByAction('user','index')">
								<a href="javascript:void(0)" onclick="add_user(this)" class="btn btn-primary btn-sm pull-left" style="margin-right:8px"><i class="fa fa-plus-circle"></i>&nbsp; 添加员工</a>
								</if>
							</div>
							<form class="form-inline" id="" action="" method="get">
							<ul class="breadcrum pull-right" style="margin-bottom: 0px">
								<li>
									搜索：
									<div class="input-group">
										<input type="hidden" name="m" value="user"/>
										<input type="hidden" name="a" value="index"/>
										<input type="hidden" name="status" value="{$_GET['status']}"/>
										<input id="short_search" type="text" style="width:160px;" placeholder="请输入员工名称" onkeydown='if(event.keyCode==13) {$("#short_search_btn").trigger("click");return false;}' class="form-control input-sm" name="search" value="{$_GET['search']}"/>
										<span class="input-group-btn">
											<button class="btn btn-default btn-search" id="short_search_btn" type="submit"><i class="fa fa-search"></i></button>
										</span>
									</div>
								</li>
								<span style="margin-left:20px;">状态：</span>
								<select class="form-control" onchange="window.open(this.options[this.selectedIndex].value,target='_self')" style="margin-bottom:5px;">
									<option value="{:U('user/index')}">--全部--</option>
									<option value="{:U('user/index',$parameter.'&status=1')}" <if condition = "$_GET['status'] eq 1">selected</if>>已激活</option>
									<option value="{:U('user/index',$parameter.'&status=3')}" <if condition = "$_GET['status'] eq 3">selected</if>>未激活</option>
									<option value="{:U('user/index',$parameter.'&status=2')}" <if condition = "$_GET['status'] eq 2">selected</if>>已停用</option>
								</select>
							</ul>
							</form>
						</div>
					</div>
					<form action="" id="user_form" method="post" style="position:relative;" onsubmit="return false">
						<div class="col-sm-12 ibox-content" style="margin-top:0px;padding:0px;">
							<div id="table_div" class="full-height-scroll" style="left:0px;top:0px;">
								<table class="table table-hover table-striped table_thead_fixed" id="tab_Test3">
									<if condition="$user_list eq null">
										<include file="Public:nodata" />
									<else/>
										<tr colspan="7" class="tabTh">
											<td style="width:60px;">
												<div class="checkbox checkbox-primary">
													<input class="check_all" id="check_all" type="checkbox" />
													<label for=""></label>
												</div>
											</td>
											<td style="width:170px;"><span style="margin-left:30px;">员工</span></td>
											<td>登录账号</td>
											<td>员工编号</td>
											<td>角色</td>
											<td>手机号</td>
											<td>邮箱</td>
											<td>部门</td>
											<td>职位</td>
										</tr>
										<volist name="user_list" id="vo">
										<tr>
											<td style="width:60px;">
												<div class="checkbox checkbox-primary">
													<input name="user_id[]" class="check_list" type="checkbox" value="{$vo.user_id}" <if condition = "$vo['status'] eq 2">rel1="1"<elseif condition="$vo['status'] eq 3"/>rel1="3"<elseif condition="$vo['status'] eq 1"/>rel1="2"</if>/>
													<label for=""></label>
												</div>
											</td>
											<td>
												<a href="{:U('user/view','id='.$vo['user_id'])}">
												<if condition="$vo['thumb_path']">
													<img class="img-circle" style="width:32px;height:32px;" src="{$vo.thumb_path}"/>
												<else/>
													<img class="img-circle" style="width:32px;height:32px;" src="__PUBLIC__/img/avatar_default.png"/>
												</if>
												<if condition="$vo['category_id'] == 1">
													{$vo.full_name}
													<span><img src="__PUBLIC__/img/admin.png" /></span>
												<else />
													{$vo.full_name}
													<span style="width:11px;display: inline-block;"></span>
												</if>
												</a>
											</td>
											<td class="count_status">
												<if condition = "$vo['status'] eq 1">
													<if condition = "$vo['category_id'] eq 1">
														<span class="fa fa-user-circle" style="color:#5ACD61;"></span>
													<else />
														<span class="fa fa-circle" style="color:#5ACD61;"></span>
													</if>
												<elseif condition = "$vo['status'] eq 2"/>
													<span class="fa fa-circle" style="color:#FF6C62;"></span>
												<else />
													<span class="fa fa-circle" style="color:#FACB42;"></span>
												</if>
												{$vo.name}
											</td>
											<td>{$vo.number}</td>
											<td>{$vo['type_name']}</td>
											<td><if condition="C('ismobile') eq 1"><a href="tel:{$vo.telephone}">{$vo.telephone}</a><else />{$vo.telephone}</if></td>
											<td>{$vo.email}</td>
											<td>{$vo['role_info']['department_name']}</td>
											<td>{$vo['role_info']['role_name']}</td>
										</tr>
										</volist>
									</if>
								</table>
							</div>
							<div class="ibox-content" style="position:relative;padding-top: 5px;height: 40px;border: none;">
								<div class="table-content">
									<div class="ibox-span" style="margin-left:0px;">
										<span class="fa fa-user-circle" style="color:#40C053;"></span>
										<span>系统管理员</span>
									</div>
									<div class="ibox-span">
										<span class="fa fa-circle" style="color:#5ACD61;"></span>
										<span>已激活</span>
									</div>
									<div class="ibox-span">
										<span class="fa fa-circle" style="color:#FF6C62;"></span>
										<span>已停用</span>
									</div>
									<div class="ibox-span">
										<span class="fa fa-circle" style="color:#FACB42;"></span>
										<span>未激活</span>
									</div>
								</div>
							</div>
							<div id="tfoot_div" class="clearfix">
								<div class="clearfix" id="tfoot_page">
									{$page}<include file="Public:listrows" />
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
        </div>
    </div>
</div>
<div class="container-fluid" style="margin-top:10px;">
	<div class="row-fluid">
		<div class="span12">
			<div class="container2" style="padding:5px;margin:-15px 0 15px">

			</div>
			<div class="row-fluid" style="background-color:#fff">
			</div>
		</div>
	</div>
</div>
<div id="dialog-message" style="display:none;" title="{:L('DIALOG_ASSIGN_POSITION')}">
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div>
		</div>
	</div>
</div>
<if condition="session('?admin')">
<div id="dialog-message2" style="display:none;" title="{:L('DIALOG_ADD_DEPARTMENT')}">
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div>
		</div>
	</div>
</div>
</if>
<div id="dialog-message3" style="display:none;" title="{:L('DIALOG_ADD_POSITION')}">
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div>
		</div>
	</div>
</div>
<div id="dialog-reset_password" style="display:none;" title="重置密码">
	<table class="table">
		<tr>
			<td style="margin:auto;">
				<input type="password" name="new_password" id="new_password" class="form-control" value="" placeholder="请输入新密码" style="width:240px;float:left;margin-left:115px;" />
				<a href="javascript:void(0)" class="btn btn-primary" onclick="reset_form(this)" style="background-color:#3181E2;float:left;margin-left:10px;">重置</a>
			</td>
		</tr>
		<tr>
			<td style="text-align:center;color:#999;"></span>重置后请告知员工，以确保其正常登录</span></td>
		</tr>
	</table>
</div>
<!-- 模态框 -->
<div class="modal inmodal fade" id="Modal" tabindex="1" style="overflow:auto; border:1px solid #000000;" role="dialog" >
    <div class="modal-dialog modal-md" style="width:700px;">
        <div class="modal-content" id="dep_modal">
            
        </div>
    </div>
</div>
<script type="text/javascript">
/*模态框关闭或打开 先清除内容*/
$(".modal").on("hide.bs.modal", function() {
    $(this).removeData("bs.modal");
});
$(".modal").on("show.bs.modal", function() {
    $(this).removeData("bs.modal");
});
/*让复选框默认取消选择*/
$(':checkbox').prop('checked', false);

$(function(){
	$("#edit_user").click(function(){
		window.location.href="{:U('user/edit','&id=')}"+$(this).attr('rel');
	})
	$("#check_all").click(function(){
		$("input[class='check_list']").prop('checked', $(this).prop("checked"));
	});
	<if condition="session('?admin')">
		$("#add_department").click(function(){
			$('#dialog-message2').dialog('open');$('#dialog-message2').load('{:U("user/department_add")}');
		});
	</if>
	$("#add_role").click(function(){
		$('#dialog-message3').dialog('open');
		$('#dialog-message3').load('{:U("user/role_add")}');
	});
	$(".role").click(function(){
		$('#dialog-message').dialog('open');
		id = $(this).attr('rel');
		$('#dialog-message').load('{:U("User/user_role_relation","by=user_role&id=")}'+id);
	});
	$("#reset_password").click(function(){
		$('#dialog-reset_password').dialog('open');
	});
});
function searchUser(){
	var objCategory=document.getElementById("categoryList");
	var id=objCategory.options[objCategory.selectedIndex].value;
	window.location="{:U('user/index','id=')}"+id;
}

function changeContent(){
	a = $("#select1  option:selected").val();
	if(a=='1'){
		window.location.href="{:U('user/index')}";
	}else if(a=='2'){
		window.location.href="{:U('user/index', 'status=0')}";
	}else if(a=='3'){
		window.location.href="{:U('user/index', 'status=-1')}";
	}else if(a=='4'){
		window.location.href="";
	}else if(a=='5'){
		window.location.href="{:U('user/department')}{:U('user/role')}";
	}
}
<if condition="C('ismobile') eq 1">width=$('.container').width() * 0.9;<else/>width=600;</if>
$('#dialog-message').dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position :["center",100]
});
<if condition="session('?admin')">
$('#dialog-message2').dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position :["center",100],
	buttons: {
		"{:L('OK')}": function () {
			$('#department_add').submit();
			$(this).dialog("close");
		},
		"{:L('CANCEL')}": function () {
			$(this).dialog("close");
		}
	}
});
$('#dialog-reset_password').dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position :["center",100]
});
function del_user(status){
	var status = status;
	var status_name = '停用';
	if(status == 2){
		status_name = '启用';
	}else if(status==3){
        status_name = '激活';
	}
	let formdata = $("#user_form").serialize();
	formdata = formdata+"&status="+status;
	swal({
		title: "温馨提示",
		text: "您确定要"+status_name+"此账号吗？",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: "#DD6B55",
		confirmButtonText: "是的，我要"+status_name+"！",
        cancelButtonText:'让我再考虑一下…',
        closeOnConfirm:false,
        closeOnCancel:false
	},
	function(isConfirm){
	    if (isConfirm) {
			$.ajax({
				type: "POST",
				url: "{:U('user/delete')}",
				data:formdata,
				async: true,
				success: function(data) {
					if(data.status == 1){
						swal({
							title: "操作成功！",
							text: "即将刷新页面!",
							type: "success"
						});
						location.reload();
					}else{
						 swal({
							title: "操作失败!",
							text: data.info,
							type: "error"
						});
					}
				}
			});
		} else {
            swal("已取消","您取消了"+status_name+"操作！","error");
        }
	});
}
</if>
$('#dialog-message3').dialog({
	autoOpen: false,
	modal: true,
	width: width,
	maxHeight: 400,
	position :["center",100],
	buttons: {
		"{:L('OK')}": function () {
			$('#role_add').submit();
			$(this).dialog("close");
		},
		"{:L('CANCEL')}": function () {
			$(this).dialog("close");
		}
	}
});
function reset_form(obj){
	var user_id = $('#reset_password').attr('rel');
	var new_pass = $('#new_password').val();
	if(typeof(new_pass) != 'undefined'){
		if(new_pass.length < 6 || new_pass.length > 16){
			alert_crm('密码长度应为6~16位字符！');
			return false;
		}else{
			swal({
				title: "温馨提示",
				text: "确定要将密码重置为:"+new_pass+"吗？",
				type: "warning",
				showCancelButton: true,
				closeOnConfirm: false
			},
			function(){
				$.ajax({
					type: "GET",
					url: "{:U('user/reset_password')}&id="+user_id+'&new_password='+new_pass,
					async: true,
					success: function(data) {
						if(data.status == 1){
							swal({
								title: "重置成功！",
								text: "即将刷新页面!",
								type: "success"
							});
							$('#dialog-reset_password').dialog("close");
							location.reload();
							//window.location.href="{:U('user/index')}";
						}else{
							swal({
								title: "操作失败!",
								text: data.info,
								type: "error"
							});
						}
					}
				});
			});
		}
	}else{
		swal({
			title: "",
			text: "重置密码不能为空！"
		})
		return false;
	}
}
function add_user(obj){
	$("#dep_modal").parent().removeClass("modal-lg").addClass("modal-md");
	var url = "{:U('user/user_add')}";
	$('#Modal').modal('show');
    $('#dep_modal').load(url);
}
</script>
<include file="Public:footer" />	